//
//  CMHelper.m
//  BlackBambooCM-OC
//
//  Created by 宜凯门-DKang on 2018/10/11.
//  Copyright © 2018年 ucanmax. All rights reserved.
//

#import "CMHelper.h"
#import "CMLoginViewController.h"
#import "CYLTabBarControllerConfig.h"
/**
 
 */
@implementation CMHelper
// 读取本地JSON文件
+ (NSArray *)readLocalFileWithName:(NSString *)name {
    NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"json"];
    NSData *jsonData = [[NSData alloc] initWithContentsOfFile:path];
    NSArray*jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    return jsonArray;
}

+ (NSString*)dictionaryToJson:(NSDictionary *)dict {
    NSError *parseError =nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&parseError];
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
//获取当前时间戳
+ (NSString *)currentTimeStr{
    NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0];//获取当前时间0秒后的时间
    NSTimeInterval time=[date timeIntervalSince1970]*1000;// *1000 是精确到毫秒，不乘就是精确到秒
    NSString *timeString = [NSString stringWithFormat:@"%.0f", time];
    NSUserDefaults *uds = [NSUserDefaults standardUserDefaults];
    [uds setValue:timeString forKey:TimeString];
    [uds synchronize];
    return timeString;
}
+ (NSString *) getUpLocalTimeStr {
    NSUserDefaults *uds = [NSUserDefaults standardUserDefaults];
    NSString *timeString = [uds objectForKey:TimeString];
    return timeString;
}
- (void) goLogin {
    CMLoginViewController *login = [[CMLoginViewController alloc]initWithNibName:@"CMLoginViewController" bundle:[NSBundle mainBundle]];
    UINavigationController *loginNavi =[[UINavigationController alloc] initWithRootViewController:login];
    [[[AppDelegate shareAppDelegate] getCurrentVC] presentViewController:loginNavi animated:YES completion:nil];
}
@end
